package com.tjh.springbootapi.controller;

import com.tjh.springbootapi.SpringbootApiApplication;
import com.tjh.springbootapi.entity.EmployeeDO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

//测试用例
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ThreadTest01.class, SpringbootApiApplication.class})
public class ThreadTest01 {

    @Resource
    private EmployeeBO employeeBO;

    /**
     * 测试多线程事务.
     *
     * @throws InterruptedException
     */
    @Test
    public void MoreThreadTest2() throws InterruptedException {
        int size = 10;
        List<EmployeeDO> employeeDOList = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            EmployeeDO employeeDO = new EmployeeDO();
            employeeDO.setEmployeeName("lol" + i);
            /*employeeDO.setAge(18);
            employeeDO.setGender(1);
            employeeDO.setIdNumber(i+"XX");
            employeeDO.setCreatTime(Calendar.getInstance().getTime());*/
            employeeDOList.add(employeeDO);
        }
        try {
            employeeBO.saveThread2(employeeDOList);
            System.out.println("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}